package com.ntt.benew.dictionary.view

import android.content.Context
import android.graphics.Typeface
import android.util.AttributeSet
import android.view.Gravity
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.view.size
import com.blankj.utilcode.util.SizeUtils
import com.ntt.benew.dictionary.R

/**
 * Created by Android Studio.
 * User: tw
 * Date: 2023/11/2
 * Time: 21:07
 */
class WordDetailTitleView(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) {

    private lateinit var mTitleView: TextView

    init {
        orientation = HORIZONTAL
        createTriangle()
        gravity = Gravity.CENTER_VERTICAL
    }

    private fun createTriangle() {
        val iv = ImageView(context).apply {
            setImageDrawable(ContextCompat.getDrawable(context, R.drawable.icon_inverted_triangle))
            scaleType = ImageView.ScaleType.CENTER_INSIDE
        }
        addView(iv)
        createTitle()
    }

    private fun createTitle() {
        mTitleView = TextView(context).apply {
            textSize = 22f
            setTextColor(ContextCompat.getColor(context, R.color.ntt_26323F))
            typeface = Typeface.defaultFromStyle(Typeface.BOLD)
            val params = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
            params.marginStart = SizeUtils.dp2px(10f)
            layoutParams = params

        }
        addView(mTitleView)
    }

    fun setText(txt: String?) {
        if (::mTitleView.isInitialized) {
            mTitleView.text = txt
        }
    }

}